package com.css.fxfzaqbz.modules.callJcData.controller;

import com.css.fxfzaqbz.util.RestTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.slw.common.helper.PropsHelper;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author y1fan
 * @create 2023-01-09 17:46
 * 调用数据系统的接口
 */
@RestController
@RequestMapping("/fxfzaqbz/jcData")
@Slf4j
public class CallJcDataController {

    @Resource
    private RestTemplateUtil restTemplateUtil;

    Properties configGroup = PropsHelper.loadProps("slw-config.properties");
    //类型接口路径
    String lxUrl = configGroup.getProperty("restTemplateUrl") + "/test/dictItems/getDataTypeLevel2AndDataTypeLevel3Tree";
    String bbUrl = configGroup.getProperty("restTemplateUrl") + "/datacenter/sysDataVersion/list";
    String cxUrl = configGroup.getProperty("restTemplateUrl") + "/datacenter/sysDataVersion/queryDataByVersionCode";
    String cxByIdUrl = configGroup.getProperty("restTemplateUrl") + "/datacenter/sysDataVersion/queryDataById";

    /*
    * 调用基础数据系统 查类型接口
    * */
    @GetMapping("getDataTypeLevel2AndDataTypeLevel3TreeForSubsystem")
    public String getDataTypeLevel2AndDataTypeLevel3TreeForSubsystem() {
        Map<String, Object> paramMap = new HashMap<>();
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendHttpRequestPj(lxUrl, paramMap);
        return stringResponseEntity.getBody();

    }

    /*
    *版本接口
    * */
    @PostMapping("list")
    public String list(@RequestBody Map<String,Object> map) {
        //dataRangeCountry,dataRangeProvince,dataRangeCity,dataRangeArea,dataType2,versionCode
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendHttpRequestPj(bbUrl, map);
        return stringResponseEntity.getBody();
    }


    /*
    * 根据数据版本查询
    * */
    @PostMapping("queryDataByVersionCode")
    public String queryDataByVersionCode(@RequestBody Map<String,Object> map) {
        //versionCode,typeCode
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendHttpRequestPj(cxUrl, map);
        return stringResponseEntity.getBody();
    }


    /*
    * 根据id查询单条数据
    * */
    @PostMapping("queryDataById")
    public String queryDataById(@RequestBody Map<String,Object> map) {
        //id,typeCode
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendHttpRequestPj(cxByIdUrl, map);
        return stringResponseEntity.getBody();
    }










}
